import { useSelector, useDispatch } from "react-redux"

export default () => {
  // let { size } = useSelector(function (state) {
  //   // console.log("获取仓库中的状态：", state);
  //   return state.app
  // })
  // console.log(size);

  let { size } = useSelector(state => state.app)
  let dispatch = useDispatch();
  console.log(size);

  // let { userInfo } = useSelector(state => state.user)
  // console.log(userInfo);

  const sizeAdd = () => {
    // 在修改状态，需要dispath一个action
    dispatch({type:"APP_SIZE_ADD",payload:2})
  }
  const sizeSub = () => {
    dispatch({ type: "APP_SIZE_SUB", payload: 3 })
  }
  return (
    <div>
      <h2>商品列表</h2>
      <h2>{size}</h2>
      <button onClick={sizeAdd}>size++</button>
      <button onClick={sizeSub}>size--</button>
    </div>
  )
}
